/**
 * 集群模块控制器
 * 
 * @author zhongfuhua
 */
var jobApp = angular.module("jobApp", ["publicServiceApp", "jobServiceApp", "jobGroupServiceApp", "jobIdentityInfoServiceApp",
	"taskConnectInfoServiceApp", "taskIdentityServiceApp","clusterServiceApp", "jobDetailServiceApp","jobDetailTrackServiceApp",
	"jobDeathServiceApp", "ngJsTree", "ngSelect2"]);

jobApp.controller("jobCtrl", [
		"$scope",
		"commonService",
		"publicService",
		"jobService",
		"jobGroupService",
		"jobIdentityInfoService",
		"taskConnectInfoService",
		"taskIdentityService",
		"clusterService",
		"jobDetailService",
		"jobDetailTrackService",
		"jobDeathService",
		"$timeout",
		"$log",
		function($scope, commonService, publicService, jobService, jobGroupService, 
				jobIdentityInfoService, taskConnectInfoService, taskIdentityService, clusterService, 
				jobDetailService, jobDetailTrackService, jobDeathService, $timeout, $log) {
			
			
			// 表格
			$scope.$jobTable = $('#jobTable');
			$scope.$taskConnectionInfoTable = $('#taskConnectionInfoTable');
			$scope.$taskIdentityTable = $('#taskIdentityTable');
			$scope.$jobDetailRunningTable = $('#jobDetailRunningTable');
			$scope.$jobDetailRetryTable = $('#jobDetailRetryTable');
			$scope.$jobDetailDeathTable = $('#jobDetailDeathTable');
			
			// 按钮
			$scope.$jobAddButton = $('#jobAddButton');
			$scope.$jobModButton = $('#jobModButton');
			$scope.$jobRemoveButton = $('#jobRemoveButton');
			$scope.$jobStopButton = $('#jobStopButton');
			$scope.$jobResumeButton = $('#jobResumeButton');
			$scope.$jobClearDetailButton = $('#jobClearDetailButton');
			
			$scope.$jobDetailInterruptButton = $('#jobDetailInterruptButton');
			$scope.$jobDetailResetButton = $('#jobDetailResetButton');
			$scope.$jobDetailFinishButton = $('#jobDetailFinishButton');
			$scope.$jobDetailDeathResetButton = $('#jobDetailDeathResetButton');
			$scope.$jobDetailDeathFinishButton = $('#jobDetailDeathFinishButton');
			
			// 模态框
			$scope.$jobModal = $('#jobModal');
			$scope.$jobDetailModal = $('#jobDetailModal');
			$scope.$jobIdentityInfoModal = $('#jobIdentityInfoModal');
			$scope.$taskConnectionInfoModal = $('#taskConnectionInfoModal');
			$scope.$jobDetailRunningModal = $('#jobDetailRunningModal');
			$scope.$jobDetailRetryModal = $('#jobDetailRetryModal');
			$scope.$jobDetailDeathModal = $('#jobDetailDeathModal');
			$scope.$jobDetailRunningThreadModal = $('#jobDetailRunningThreadModal');
			
			// 表格选中实例对象
			$scope.selectionIds = new Array();
			$scope.selections = new Array();
			
			$scope.taskIdentitySelectionIds = new Array();
			$scope.taskIdentitySelections = new Array();
			
			// 监视isSucce的状态
			$scope.action = null;
			$scope.isSuccess = true;
			$scope.error = null;
			
			// vo
			$scope.userName = null;
			$scope.publicVO = {};
			$scope.jobVO = {
					jobTimeoutPolicy : "TRANSFER",
					bufferSizeLimit : 5000,
					repeatInterval : 60000,
					repeatCount : -1,
					executeTimeout : -1,
					jobType : "STATEFUL",
					jobRepeatType : "NORMAL",
					jobMisfireInstruction : "RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT",
					resetDeathDelayTime : -1,
					priority : 1
			};
			$scope.jobIdentityInfoVO = {};
			$scope.jobDetailDeathVO = {};
			$scope.taskConnectInfoVO = {};
			$scope.jobIdentityInfoTableCurrent = null;
			
			// 下拉框
			$scope.jobGroupSelectConfig = {
					minimumResultsForSearch : 1, // 是否打开搜索
					data : [],			 
					placeholder : '如无选项请新增任务组'			 // 占位符
			};
			
			$scope.repeatTypeSelectConfig = {
					minimumResultsForSearch : 1, // 是否打开搜索
					data : [{text:"普通", id:"NORMAL"},
					        {text:"cron表达式", id:"CRON"}],			 
					placeholder : '请选择'			 // 占位符
			};
			
			$scope.jobTypeSelectConfig = {
					minimumResultsForSearch : 1, // 是否打开搜索
					data : [{text:"无状态", id:"NORMAL"},
					        {text:"有状态", id:"STATEFUL"}],			 
					placeholder : '请选择'			 // 占位符
			};
			
			$scope.misfireInstructionSelectConfig = {
					minimumResultsForSearch : 1, // 是否打开搜索
					data : [{text:"马上执行", id:"IGNORE_MISFIRE_POLICY"},
					        {text:"忽略跳过(普通)", id:"RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT"},
					        {text:"忽略跳过(cron)", id: "DO_NOTING"}],			 
					placeholder : '请选择'			 // 占位符
			};
			
			
			$scope.jobTimeoutPolicySelectConfig = {
					minimumResultsForSearch : 1, // 是否打开搜索
					data : [{text:"忽略", id:"IGNORE"},
					        {text:"转移", id:"TRANSFER"},
					        {text:"结束", id:"FINISH"}],			 
					placeholder : '请选择'			 // 占位符
			};
			
			
			ffc.util.watchResult($scope, $timeout);
			
			/**
			 * 
			 * 功能说明:查询任务
			 * 
			 * @author ZHONGFUHUA
			 * 
			 * @Date 2016年10月25日
			 * 
			 */
			$scope.queryJobTable = function(){
				$scope.$jobTable.bootstrapTable("selectPage", 1);  
			}
			
			
			
			/**
			 * 
			 * 功能说明:查询死任务
			 * 
			 * @author ZHONGFUHUA
			 * 
			 * @Date 2016年10月25日
			 * 
			 */
			$scope.queryTaskConnectionInfoTable = function(){
				$scope.$taskConnectionInfoTable.bootstrapTable("selectPage", 1);  
			}
			
			
			
			/**
			 * 
			 * 功能说明:查询执行端
			 * 
			 */
			$scope.queryTaskIdentity = function(){
				$scope.$taskIdentityTable.bootstrapTable("selectPage", 1);  
			}
			
			/**
			 * 
			 * 功能说明:查询运行中任务
			 * 
			 */
			$scope.queryJobDetailRunning = function(){
				$scope.$jobDetailRunningTable.bootstrapTable("selectPage", 1);  
			}
			
			/**
			 * 
			 * 功能说明:查询死任务
			 * 
			 */
			$scope.queryJobDetailDeath = function(){
				$scope.$jobDetailDeathTable.bootstrapTable("selectPage", 1);  
			}
			
			
			/**
			 * 
			 * 功能说明:查询待执行任务
			 * 
			 */
			$scope.queryJobDetailRetry = function(){
				$scope.$jobDetailRetryTable.bootstrapTable("selectPage", 1);  
			}
			
			/**
			 * 
			 * 功能说明:查询执行端信息
			 * 
			 */
			$scope.queryJobIdentityInfo = function(){
				if($scope.jobIdentityInfoTableCurrent != null &&  $scope.jobIdentityInfoTableCurrent != undefined){
					$scope.jobIdentityInfoTableCurrent.bootstrapTable("selectPage", 1); 
				}
			}
			
			/**
			 * 
			 * 功能说明:新增修改集群
			 * 
			 */
			$scope.saveJob = function(){
				if($scope.jobForm.$invalid){
					new MessageDialog().error("配置填写不规范，请重新填写！！！")
					return;
				}
				
				if($scope.jobVO.jobRepeatType == "CRON"){
					if($scope.jobVO.jobMisfireInstruction == "RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT"){
						$scope.jobVO.jobMisfireInstruction = "DO_NOTING";
					}
				}
				
				if($scope.action=="MOD"){
					jobService.update($scope.jobVO, function(result){
						if(!result.result){
							$scope.error = result.msgTitle;
							$scope.isSuccess = false;
							return false;
						}
						new MessageDialog().success("修改成功!!");
						$scope.$jobModal.modal("hide");
						$scope.$jobTable.bootstrapTable("selectPage", 1);  
					},function(error){
						$scope.error = error;
						$scope.isSuccess = false;
					});
				}else{
					$scope.jobVO.clusterName = $scope.jobVO.jobGroup.clusterName;
					jobService.add($scope.jobVO, function(result){
						if(!result.result){
							$scope.error = result.msgTitle;
							$scope.isSuccess = false;
							return false;
						}
						new MessageDialog().success("添加成功!!");
						$scope.$jobModal.modal("hide");
						$scope.queryJobTable();
					},function(error){
						$scope.error = error;
						$scope.isSuccess = false;
					});
				}
			}
			
			/**
			 * 
			 * 功能说明:删除集群
			 * 
			 */
			$scope.deleteJob = function(){
				new MessageDialog().confirm("确定删除？", function() {
					var deleteObjs = new Array();
					angular.forEach($scope.selections, function(data, index, array){
						deleteObjs.push({id : data.id, clusterName : data.clusterName});
					});
					
					jobService.removeList(deleteObjs, function(result){
						if(!result.result){
							$scope.error = result.msgTitle;
							$scope.isSuccess = false;
							return false;
						}
						new MessageDialog().success("删除成功");
						$scope.queryJobTable();
					},function(error){
						$scope.error = error;
						$scope.isSuccess = false;
					});
			   });
			}
			
			
			/**
			 * 
			 * 功能说明:暂停任务
			 * 
			 */
			$scope.pauseJob = function(){
				new MessageDialog().confirm("确定暂停任务？", function() {
					jobService.pause($scope.selections, function(result){
						if(!result.result){
							$scope.error = result.msgTitle;
							$scope.isSuccess = false;
							return false;
						}
						new MessageDialog().success("暂停成功!!");
					},function(error){
						$scope.error = error;
						$scope.isSuccess = false;
					});
			   });
			}
			
			
			/**
			 * 
			 * 功能说明:唤醒任务
			 * 
			 */
			$scope.resumeJob = function(){
				new MessageDialog().confirm("确定唤醒任务？", function() {
					jobService.resume($scope.selections, function(result){
						if(!result.result){
							$scope.error = result.msgTitle;
							$scope.isSuccess = false;
							return false;
						}
						new MessageDialog().success("唤醒成功!!");
					},function(error){
						$scope.error = error;
						$scope.isSuccess = false;
					});
			   });
			}
			
			
			/**
			 * 
			 * 功能说明:清空子任务
			 * 
			 */
			$scope.removeJobDetail = function(){
				new MessageDialog().confirm("确定清空子任务？", function() {
					jobService.removeJobDetail($scope.selections, function(result){
						if(!result.result){
							$scope.error = result.msgTitle;
							$scope.isSuccess = false;
							return false;
						}
						new MessageDialog().success("清空成功!!");
					},function(error){
						$scope.error = error;
						$scope.isSuccess = false;
					});
			   });
			}
			

			/**
			 * 
			 * 功能说明:新增修改集群
			 * 
			 */
			$scope.selectTaskIdentity = function(){
				new MessageDialog().confirm("确定添加选中的实例？", function() {
					var jobIdentityInfoVoList = new Array();
					angular.forEach($scope.taskIdentitySelections, function(data, index, array){
						var jobIdentityInfoVo = {
							jobId : $scope.jobIdentityInfoVO.jobId,
							taskIdentityId : data.id,
							description : data.name,
							identity : data.identity,
							clusterName : $scope.jobIdentityInfoVO.clusterName
						}
						jobIdentityInfoVoList.push(jobIdentityInfoVo);
					});
					
					jobIdentityInfoService.addList(jobIdentityInfoVoList, function(result){
						if(!result.result){
							$scope.error = result.msgTitle;
							$scope.isSuccess = false;
							return false;
						}
						new MessageDialog().success("添加成功!!");
						$scope.$jobIdentityInfoModal.modal("hide");
						$scope.queryJobIdentityInfo();  
					},function(error){
						$scope.error = error;
						$scope.isSuccess = false;
					});
				});
			}
			
			/**
			 * 
			 * 功能说明:删除集群
			 * 
			 * @author ZHONGFUHUA
			 * 
			 * @Date 2016年10月25日
			 * 
			 */
			$scope.deleteJobIdentityInfo = function(){
				new MessageDialog().confirm("确定删除？", function() {
					jobIdentityInfoService.remove($scope.jobIdentityInfoVO, function(result){
						if(!result.result){
							$scope.error = result.msgTitle;
							$scope.isSuccess = false;
							return false;
						}
						new MessageDialog().alert("删除成功!!");
						$scope.queryJobIdentityInfo();
					},function(error){
						$scope.error = error;
						$scope.isSuccess = false;
					});
			   });
			}
			
			
			/**
			 * 
			 * 功能说明:查询任务组下拉框数据
			 * 
			 * @author ZHONGFUHUA
			 * 
			 * @Date 2016年10月25日
			 * 
			 */
			$scope.queryJobGroupSelect = function(){
				jobGroupService.query({}, function(result){
					if(!result.result){
						$scope.error = result.msgTitle;
						$scope.isSuccess = false;
						return false;
					}
					$scope.jobGroupSelectConfig.data  = new Array();
					angular.forEach(result.dataList, function(data, index, array){
						var option = {
								id : data.id,
								text : data.name,
								clusterName : data.clusterName
						}
						$scope.jobGroupSelectConfig.data.push(option);
					});
					ffc.util.angularApply($scope, $timeout);
				},function(error){
					$scope.error = error;
					$scope.isSuccess = false;
				});
			}

			/**
			 * 
			 * 功能说明:查询所有菜单，父子结构展示
			 * 
			 * @author ZHONGFUHUA
			 * 
			 * @Date 2016年10月20日
			 * 
			 */
			$scope.queryCurrentUser = function(){
				publicService.queryCurrentUser({}, function(data) {
					$scope.userName = data.userName;
				}, function(error) {
					$scope.error = error;
					$scope.isSuccess = false;
				});
			}
			
			$(function() {
				
				$scope.queryJobGroupSelect();
				$scope.queryCurrentUser();
				
				/**
				 * 
				 * 功能说明:初始化数据源表格
				 * 
				 * @author ZHONGFUHUA
				 * 
				 * @Date 2016年10月25日
				 * 
				 */
				$scope.$jobTable.bootstrapTable({
					queryParams : function(params) {
						var selfParams = {
							name : $scope.jobVO.queryName,
							jobGroupId : $scope.jobVO.queryJobGroupId,
							identity : $scope.jobVO.queryIdentity,
							description : $scope.jobVO.queryDescription
						}
						return $.extend({}, params, selfParams);
					},
					ajax : function(render) {
						jobService.queryPage(render.data, function(result) {
							if(!result.result){
								$scope.error = result.msgTitle;
								$scope.isSuccess = false;
								return false;
							}
							ffc.util.loadTableData(render, result);  
						},function(error){
							$scope.error = error;
							$scope.isSuccess = false;
						});
						$scope.$jobRemoveButton.prop('disabled', true);
						$scope.$jobModButton.prop('disabled', true);
						$scope.$jobStopButton.prop('disabled', true);
						$scope.$jobResumeButton.prop('disabled', true);
						$scope.$jobClearDetailButton.prop('disabled', true);
						
					},
					onExpandRow : function(index, row, $detail){
						var jobIdentityInfoTable = $detail.html(
								"<div class=\"table-responsive\">" +
									"<table name='jobIdentityInfoTable'></table>" +
								"</div>"
								).find("table");
						
						var columns = [];
						
						columns.push({
							field : "identity",
							title : "标识",
							align : "center",
							classes : "table-column",
							valign : "middle"
						});
						
						columns.push({
							field : "description",
							title : "备注",
							align : "center",
							classes : "table-column",
							valign : "middle"
						});
						
						columns.push({
							title : "操作",
							width : "15%",
							align : "center",
							classes : "table-column operation",
							valign : "middle",
							formatter : jobIdentityInfoFormatter,
							events : jobIdentityInfoEvents
						});
						
						
						$scope.jobIdentityInfoTableCurrent = jobIdentityInfoTable;
						
						jobIdentityInfoTable.bootstrapTable({
							idField : "id",
							sidePagination: "server",
							columns : columns,
							pagination : true,
							pageList : [5, 10, 20],
							detailView : false,
							queryParamsType : "",
							queryParams : function(params) {
								var selfParams = {
									jobId : row.id,
									clusterName : row.clusterName
								};
								return $.extend({}, params, selfParams);
							},
							ajax : function(render) {
								jobIdentityInfoService.queryPage(render.data, function(result) {
									if(!result.result){
										$scope.error = result.msgTitle;
										$scope.isSuccess = false;
										return false;
									}
									ffc.util.loadTableData(render, result);  
								},function(error){
									$scope.error = error;
									$scope.isSuccess = false;
								});
							}
						});
					}
				});
				
				
				/**
				 * 
				 * 功能说明:初始化数据源表格
				 * 
				 */
				$scope.$taskConnectionInfoTable.bootstrapTable({
					queryParams : function(params) {
						var selfParams = {
							jobName : $scope.taskConnectInfoVO.jobName,
							clusterName : $scope.taskConnectInfoVO.clusterName,
						}
						return $.extend({}, params, selfParams);
					},
					ajax : function(render) {
						taskConnectInfoService.queryPage(render.data, function(result) {
							if(!result.result){
								$scope.error = result.msgTitle;
								$scope.isSuccess = false;
								return false;
							}
							ffc.util.loadTableData(render, result);  
						},function(error){
							$scope.error = error;
							$scope.isSuccess = false;
						});
					}
				});
				
				/**
				 * 
				 * 
				 * 
				 */
				$scope.$taskIdentityTable.bootstrapTable({
					queryParams : function(params) {
						var selfParams = {
							jobGroupId : $scope.jobIdentityInfoVO.jobGroupId,
							clusterName : $scope.jobIdentityInfoVO.clusterName,
							name : $scope.jobIdentityInfoVO.queryName,
							identity : $scope.jobIdentityInfoVO.queryIdentity
						}
						return $.extend({}, params, selfParams);
					},
					ajax : function(render) {
						taskIdentityService.queryPage(render.data, function(result) {
							if(!result.result){
								$scope.error = result.msgTitle;
								$scope.isSuccess = false;
								return false;
							}
							ffc.util.loadTableData(render, result);  
						},function(error){
							$scope.error = error;
							$scope.isSuccess = false;
						});
					}
				});
					
				
				/**
				 * 
				 * 功能说明:每次选择时重新获取表格中被选中对象
				 * 
				 */
				$scope.$jobTable.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table',function () {
					$scope.$jobModButton.prop('disabled', !$scope.$jobTable.bootstrapTable('getSelections').length);
					$scope.$jobRemoveButton.prop('disabled', !$scope.$jobTable.bootstrapTable('getSelections').length);
					$scope.$jobStopButton.prop('disabled', !$scope.$jobTable.bootstrapTable('getSelections').length);
					$scope.$jobResumeButton.prop('disabled', !$scope.$jobTable.bootstrapTable('getSelections').length);
					$scope.$jobClearDetailButton.prop('disabled', !$scope.$jobTable.bootstrapTable('getSelections').length);
					
					$scope.selectionIds = new Array();
					$scope.selections = new Array();
					angular.forEach($scope.$jobTable.bootstrapTable('getSelections'), function(data, index, array) {
						$scope.selectionIds.push(data.id);
						$scope.selections.push(data);
					});
				})
				
				
				/**
				 * 
				 * 功能说明:每次选择时重新获取表格中被选中对象
				 * 
				 */
				$scope.$taskIdentityTable.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table',function () {
					$scope.taskIdentitySelectionIds = new Array();
					$scope.taskIdentitySelections = new Array();
					angular.forEach($scope.$taskIdentityTable.bootstrapTable('getSelections'), function(data, index, array) {
						$scope.taskIdentitySelectionIds.push(data.id);
						$scope.taskIdentitySelections.push(data);
					});
				})
				
				
				
				
				
				
				/**
				 * 
				 * 功能说明:每次选择时重新获取表格中被选中对象
				 * 
				 */
				$scope.$jobTable.on('load-success.bs.table', function (data) {
					$('[data-toggle="tooltip"]').tooltip();
				});
				
				
				/**
				 * 
				 * 功能说明:弹出框关闭事件
				 * 
				 */
				$scope.$jobModal.on("hidden.bs.modal",function(){
					$scope.action = null;
					var queryJobGroupId = $scope.jobVO.queryJobGroupId;
					var queryDescription = $scope.jobVO.queryDescription;
					var queryName = $scope.jobVO.queryName;
					$scope.jobVO = {
							queryName : queryName,
							queryJobGroupId : queryJobGroupId,
							queryDescription : queryDescription,
							jobTimeoutPolicy : "TRANSFER",
							bufferSizeLimit : 5000,
							repeatInterval : 60000,
							repeatCount : -1,
							executeTimeout : -1,
							resetDeathDelayTime : -1,
							jobType : "STATEFUL",
							jobRepeatType : "NORMAL",
							jobMisfireInstruction : "RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT",
							priority : 1
					};
					$scope.jobForm.$setPristine();
				});
				
				
				/**
				 * 
				 * 功能说明:弹出框打开事件
				 * 
				 */
				$scope.$jobModal.on('shown.bs.modal',function(){
					if($scope.action=="MOD"){
						if($scope.selections.length > 1){
							$scope.$jobModal.modal("hide");
							new MessageDialog().warning("只能选择一条记录！");
							return false;
						} 
						var queryJobGroupId = $scope.jobVO.queryJobGroupId;
						var queryDescription = $scope.jobVO.queryDescription;
						var queryName = $scope.jobVO.queryName;
						$scope.jobVO = angular.copy($scope.selections[0]);
						$scope.jobVO.queryJobGroupId = queryJobGroupId;
						$scope.jobVO.queryDescription = queryDescription;
						$scope.jobVO.queryName = queryName;
						$("#jobName").attr("readonly", "readonly");
						ffc.util.angularApply($scope, $timeout);
					}else{
						$("#jobName").removeAttr("readonly", "readonly");
						$scope.queryJobGroupSelect();
					}
				});
				
				
				/**
				 * 
				 * 功能说明:格式化表格输出
				 * 
				 */
				jobTypeFormatter = function(value, row, index) {
					if(value == "NORMAL"){
						return "无状态";
					}else{
						return "有状态";
					}
					return value;
				}
				
				/**
				 * 
				 * 功能说明:格式化表格输出
				 * 
				 */
				repeatTypeFormatter = function(value, row, index) {
					if(value == "NORMAL"){
						return "普通";
					}else{
						return "CRON表达式";
					}
					return value;
				}
				
				/**
				 * 
				 * 功能说明:格式化表格输出
				 * 
				 */
				repeatCountFormatter = function(value, row, index) {
					if(value == -1){
						return "无限次";
					} 
					return value;
				}
				
				/**
				 * 
				 * 功能说明:格式化表格输出
				 * 
				 */
				jobIdentityInfoFormatter = function(value, row, index) {
					return "<a class=\"operation-del\"><i class=\"glyphicon glyphicon-trash\"></i>删除</a>";
				}
				
				/**
				 * 
				 * 功能说明:格式化表格输出
				 * 
				 */
				jobFormatter = function(value, row, index) {
					var button = "<button type=\"button\" class=\"btn btn-xs btn-order\" style=\"margin-right: 3px;\" title=\"任务详细配置\"><i class=\"glyphicon glyphicon-cog\"></i> 配置</button>"+
						         "<button type=\"button\" class=\"btn btn-xs btn-blue\" style=\"margin-right: 3px;\" title=\"添加执行端标识\"><i class=\"glyphicon glyphicon-plus-sign\"></i> 执行端</button>"+
						         "<button type=\"button\" class=\"btn btn-xs btn-success\" style=\"margin-right: 3px;\" title=\"在线执行端信息\"><i class=\"glyphicon glyphicon-cloud\"></i> 执行端</button>"+
						         "<button type=\"button\" class=\"btn btn-xs btn-primary\" style=\"margin-right: 3px;\" title=\"运行中的子任务\">运行中</button>"+
						         "<button type=\"button\" class=\"btn btn-xs btn-warning\" style=\"margin-right: 3px;\" title=\"待重试的子任务\">待执行</button>"+
						         "<button type=\"button\" class=\"btn btn-xs btn-danger\" style=\"margin-right: 3px;\" title=\"已卡死的子任务\">死任务</button>";
					return button;
				}
				
				
				/**
				 * 
				 * 功能说明:格式化事件
				 * 
				 */
				jobEvents = {
					'click .btn-order' : function(e, value, row, index) {
						var queryJobGroupId = $scope.jobVO.queryJobGroupId;
						var queryDescription = $scope.jobVO.queryDescription;
						var queryName = $scope.jobVO.queryName;
						
						$scope.jobVO = angular.copy(row);
						$scope.jobVO.queryJobGroupId = queryJobGroupId;
						$scope.jobVO.queryDescription = queryDescription;
						$scope.jobVO.queryName = queryName;
						
						ffc.util.angularApply($scope, $timeout);
						$scope.$jobDetailModal.modal("show");
					},	
					'click .btn-blue' : function(e, value, row, index) {
						$scope.jobIdentityInfoVO = {};
						$scope.jobIdentityInfoVO.jobId = row.id;
						$scope.jobIdentityInfoVO.jobGroupId = row.jobGroupId;
						$scope.jobIdentityInfoVO.clusterName = row.clusterName;
						$scope.actionJobIdentityInfo = "ADD";
						ffc.util.angularApply($scope, $timeout);
						$scope.queryTaskIdentity();
						$scope.$jobIdentityInfoModal.modal("show");
					},
					'click .btn-success' : function(e, value, row, index) {
						$scope.taskConnectInfoVO = {};
						$scope.taskConnectInfoVO.jobName = row.name;
						$scope.taskConnectInfoVO.clusterName = row.clusterName;
						ffc.util.angularApply($scope, $timeout);
						$scope.queryTaskConnectionInfoTable();
						$scope.$taskConnectionInfoModal.modal("show");
					},
					'click .btn-primary' : function(e, value, row, index) {
						$scope.publicVO.jobDetailRunningInit(row);
					},
					'click .btn-warning' : function(e, value, row, index) {
						$scope.publicVO.jobDetailRetryInit(row);
					},
					'click .btn-danger' : function(e, value, row, index) {
						$scope.publicVO.jobDetailDeathInit(row);
					}
				};
				
				/**
				 * 
				 * 功能说明:格式化事件
				 * 
				 */
				jobIdentityInfoEvents = {
					'click .operation-del' : function(e, value, row, index) {
						$scope.jobIdentityInfoVO = {
							id : row.id,
							clusterName : row.clusterName 
						};
						$scope.deleteJobIdentityInfo();
					}
				};
				
				/**
				 * 
				 * 功能说明:日期格式化
				 * 
				 */
				$('.date').datetimepicker({
		            format: 'yyyy-MM-dd HH:mm:ss',
		            dateIcon: 'glyphicon glyphicon-calendar'
		        });
			});
}]);
